What is term-size?
The term-size npm package is a simple utility that allows you to get the size (width and height) of the terminal window in which your Node.js application is running. It's particularly useful for CLI applications that need to adjust their output based on the available terminal space.
What are term-size's main functionalities?
Get Terminal Size
This feature allows you to retrieve the current size of the terminal (width as columns and height as rows). The code sample demonstrates how to use term-size to get the terminal dimensions and then print them to the console.
const termSize = require('term-size');
const {columns, rows} = termSize();
console.log(`Columns: ${columns}, Rows: ${rows}`);
Other packages similar to term-size
window-size
Similar to term-size, window-size is a package that can be used to get the size of the terminal window. However, window-size offers additional methods for getting size information based on different criteria (e.g., environment variables, tty dimensions), which might make it more versatile in certain scenarios.
cli-width
cli-width is another package that provides functionality to get the width of the terminal. Unlike term-size, which provides both width and height, cli-width focuses solely on the width aspect. This makes it a simpler choice if width is the only dimension you care about.
term-size
![Build Status: Windows](https://ci.appveyor.com/api/projects/status/c3tydg6uedsk0bob/branch/master?svg=true)
Reliably get the terminal window size
Because process.stdout.columns
doesn't exist when run non-interactively, for example, in a child process or when piped.
Confirmed working on macOS, Linux, and Windows.
Install
$ npm install --save term-size
Usage
const termSize = require('term-size');
termSize();
API
termSize()
Returns an Object
with columns
and rows
properties.
Related
License
MIT © Sindre Sorhus